<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div></div>
    <button id="btn">按钮</button>
    <script>
        btn.onclick = throttle(function () {
            console.log(123);
        })
        // 节流处理
        function throttle(fn) {
            return function () {
                if (window.timer) return//判断当前这一次的timer如果还在，就返回
                window.timer = setTimeout(() => {
                    fn()
                    window.timer = null//当前这一次fn执行完了，当前这一次的timer就没用了
                }, 500)
            }
        }
    </script>
</body>

</html>